home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / BTREE101.ZIP / BTSYNC.C < prev    next >
Text File  |  1990-06-20  |  1KB  |  64 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btsync.c    1.4 - 90/06/20" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8.  
  9. /* local headers */
  10. #include "btree_.h"
  11.  
  12. /*man---------------------------------------------------------------------------
  13. NAME
  14.      btsync - btree synchronize
  15.  
  16. SYNOPSIS
  17.      #include <btree.h>
  18.  
  19.      int btsync(btp);
  20.      btree_t *btp;
  21.  
  22. DESCRIPTION
  23.      The btsync function causes any buffered data for the named btree
  24.      to be written to the file.  The btree remains open and the buffer
  25.      contents remain intact.
  26.  
  27.      btsync will fail if one or more of the following is true:
  28.  
  29.      [EINVAL]       btp is not a valid btree pointer.
  30.      [BTENOPEN]     btp is not open.
  31.  
  32. SEE ALSO
  33.      btclose, btlock, btsetbuf, btsetvbuf.
  34.  
  35. DIAGNOSTICS
  36.      Upon successful completion, a value of 0 is returned.  Otherwise,
  37.      a value of -1 is returned, and errno set to indicate the error.
  38.  
  39. ------------------------------------------------------------------------------*/
  40. int btsync(btp)
  41. btree_t *btp;
  42. {
  43.     /* validate arguments */
  44.     if (!bt_valid(btp)) {
  45.         errno = EINVAL;
  46.         return -1;
  47.     }
  48.  
  49.     /* check if not open */
  50.     if (!(btp->flags & BTOPEN)) {
  51.         errno = BTENOPEN;
  52.         return -1;
  53.     }
  54.  
  55.     /* synchronize file with buffers */
  56.     if (bsync(btp->bp) == -1) {
  57.         BTEPRINT;
  58.         return -1;
  59.     }
  60.  
  61.     errno = 0;
  62.     return 0;
  63. }
  64.